
**********Table 1: The Effect of the 2010 Flood on MMA vote shares
use  "NA_regr.dta", clear

eststo aff_na: reghdfe taleb d_2013 affXt2013 if year>2002, absorb(na) cluster(na)
estadd local extra_row2 "NO"
estadd local extra_row3 "NO"
estadd local extra_row4 "NO"

eststo freqaff_na: reghdfe taleb d_2013 affXt2013 freqXt2013  if year>2002, absorb(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "NO"
estadd local extra_row4 "NO"

eststo allaff_na: reghdfe taleb d_2013 affXt2013 freqXt2013 pashtoXt2013 if year>2002, absorb(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "NO"

eststo urban: reghdfe taleb d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, absorb(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

local effect = _b[affXt2013]

label variable d_2013 "Y2013" 
label variable affXt2013  "Affected * Y2013" 

esttab aff_na freqaff_na allaff_na urban using "table1.tex" , f se label  mtitle("Share MMA" "Share MMA" "Share MMA" "Share MMA") keep(affXt2013 ) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("extra_row2 Pashtun * Y2013" "extra_row3 Freq. Flood * Y2013"  "extra_row4 Urban * Y2013") compress replace 


quietly{
su total if year==2013 & affected==1
local avg_size = round(r(mean),1)
local avg_effect = round(`effect' * `avg_size',1)


noisily: di "************************************"
noisily: di "Average extra votes in a jurisdiction"
noisily: di `avg_effect' " (of an average size of "  `avg_size' ")"
noisily: di "************************************"

total total if affected==1 & year==2013
local total_voters_aff = round(_b[total] / 1000000 ,.01)
local total_effect = round(`total_voters_aff' * `effect',.01)

noisily: di "************************************"
noisily: di "Total extra votes in affected areas"
noisily: di `total_effect' "M (where the total voters in affected areas is "  `total_voters_aff' "M)"
noisily: di "************************************" 
}
*



**********************************Table 2: The Funding Gap and MMA vote shares
use  "NA_regr.dta", clear

eststo ols_na: reghdfe taleb d_2013 freqXt2013 pashtoXt2013 urbanXt2013 FGXt2013 if year>2002, abs(na) cluster(na) 
estadd local extra_rowa "YES"
estadd local extra_rowb "YES"
estadd local extra_rowc "YES"
estadd local extra_rowd "OLS"
estadd local extra_row4 "."
estadd local extra_row5 "."

eststo fs1: reghdfe FGXt2013 d_2013 freqXt2013 pashtoXt2013 urbanXt2013 affXt2013 if year>2002 & taleb!=., abs(na) cluster(na) 
estadd local extra_rowa "YES"
estadd local extra_rowb "YES"
estadd local extra_rowc "YES"
estadd local extra_rowd "OLS"
estadd local extra_row4 "."
estadd local extra_row5 "." 

eststo iv1_na: ivreghdfe taleb d_2013 freqXt2013 pashtoXt2013 urbanXt2013 (FGXt2013 = affXt2013) if year>2002, abs(na) cluster(na)
estadd local extra_rowa "YES"
estadd local extra_rowb "YES"
estadd local extra_rowc "YES"
estadd local extra_rowd "IV" 
local F_stat = round(e(cdf),.01)
local J_test = round(e(jp),.001)
estadd local extra_row4 "`F_stat'"
estadd local extra_row5 "`J_test'"

eststo fs2: reghdfe FGXt2013 d_2013 freqXt2013 pashtoXt2013 urbanXt2013 modXt2013 sevXt2013 if year>2002 & taleb!=., abs(na) cluster(na)
estadd local extra_rowa "YES"
estadd local extra_rowb "YES"
estadd local extra_rowc "YES"
estadd local extra_rowd "OLS"
estadd local extra_row4 "."
estadd local extra_row5 "." 

eststo iv2_na: ivreghdfe taleb d_2013 freqXt2013 pashtoXt2013 urbanXt2013 (FGXt2013 = modXt2013 sevXt2013) if year>2002, abs(na) cluster(na)  
estadd local extra_rowa "YES"
estadd local extra_rowb "YES"
estadd local extra_rowc "YES"
estadd local extra_rowd "IV" 
local F_stat = string(round(e(cdf),.01) , "%9.2f")
local J_test =  string(round(e(jp),.001) , "%9.3f")
estadd local extra_row4 "`F_stat'"
estadd local extra_row5 "`J_test'"

local effect = _b[FGXt2013]

label variable d_2013  "Y2013"
label variable FGXt2013  "Funding Gap"
label variable affXt2013 "Affected * Y2013" 
label variable modXt2013 "Moderately Aff. * Y2013" 
label variable sevXt2013 "Severely Aff. * Y2013" 

esttab ols_na fs1 iv1_na fs2 iv2_na using "table2.tex" , f se label  mtitle("MMA" "Funding Gap" "MMA" "Funding Gap" "MMA") keep(FGXt2013 affXt2013 modXt2013 sevXt2013) star(* 0.10 ** 0.05 *** 0.01) ///
mgroups("OLS" "IV 1" "IV 2", pattern(1 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
scalars("extra_rowb Pashtun * Y2013" "extra_rowc Freq. Flood * Y2013" "extra_rowa  Urban * Y2013" "extra_rowd  Estimation" "extra_row4 F-stat" "extra_row5 Pvalue Overind.") compress replace 

quietly{
total total if affected==1 & year==2013
local total_voters_aff = _b[total] / 1000000
local total_effect_aid = round(`effect' * 0.6663 * `total_voters_aff',0.01)


noisily: di "************************************"
noisily: di "Total amount of people that can be moved by aid"
noisily: di `total_effect_aid' " Million"
noisily: di "************************************"

local dollar_per_person = round((1963.473246 * 0.6663) / `total_effect_aid' ,1)

noisily: di "************************************"
noisily: di "Cost of one less person voting MMA"
noisily: di `dollar_per_person' " $"
noisily: di "************************************" 

}


**********************TABLE 3 
use  "NA_regr.dta", clear

eststo sev: reghdfe taleb d_2013 modXt2013 sevXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
test _b[modXt2013] = _b[sevXt2013]

eststo indus: reghdfe taleb d_2013 dindusXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"

eststo lindus: reghdfe taleb d_2013 ldindusXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"


eststo camp:reghdfe taleb d_2013 affXt2013 LNclosestcampXt2013Xaff LNclosestcampXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"

eststo dafgh:reghdfe taleb d_2013 affXt2013 affXdafghXt2013 dafghXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"


eststo ldafgh:reghdfe taleb d_2013 affXt2013 affXldafghXt2013 ldafghXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
 
label variable affXt2013 "Affected * Y2013" 
label variable affXdafghXt2013 "Affected * Dist. Afgh. * Y2013" 

label variable modXt2013 "Moderate * Y2013" 
label variable sevXt2013 "Severe * Y2013" 
label variable dindusXt2013 "Dist. Indus * Y2013" 

esttab dafgh ldafgh sev indus lindus using "Dropbox\Latest Version\Version190205\table4.tex" , f se label mtitle("Dist. Afgh." "ln(Dist Afgh.)" "Severity" "Dist. Indus" "ln(Dist. Indus)") rename(affXldafghXt2013 affXdafghXt2013 ldindusXt2013 dindusXt2013) keep(affXt2013 affXdafghXt2013 modXt2013 sevXt2013 dindusXt2013)  ///
mgroups("Distance Afghanistan" "Severity", pattern(1 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
star(* 0.10 ** 0.05 *** 0.01) scalars("extra_row1 Pashtun * Y2013" "extra_row2 Freq. Flood * Y2013"  "extra_row3 Urban * Y2013") compress replace 


***************************
***Table 4: The Effect of the 2005 Earthquake on MMA vote shares
use  "NA_regr.dta", clear

eststo earth1:reghdfe taleb d_2008 quake200Xt2008 pashtoXt2008 earthfreqXt2008 urbanXt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"

eststo earth2:reghdfe taleb d_2008 distepiXt2008  pashtoXt2008 earthfreqXt2008 urbanXt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"

eststo earth3:reghdfe taleb d_2008 ldistepiXt2008 pashtoXt2008 earthfreqXt2008 urbanXt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"

label variable quake200Xt2008  "Aff. Earthquake * Y2008"

esttab earth1 earth2 earth3 using "table4.tex" , f se label mtitle("200Km Epi" "Dist Epi" "ln(Dist Epi)") rename(distepiXt2008 quake200Xt2008 ldistepiXt2008 quake200Xt2008) keep(quake200Xt2008)  ///
star(* 0.10 ** 0.05 *** 0.01) scalars("extra_row1 Pashtun * Y2008" "extra_row2 Freq. Earthquake * Y2008"  "extra_row3 Urban * Y2008") compress replace 


*****************************QUANTIFY EFFECT OF EARTHQUAKE
reghdfe taleb d_2008 quake200Xt2008 pashtoXt2008 earthfreqXt2008 urbanXt2008 if year<2013, abs(na) cluster(na)

local effect = _b[quake200Xt2008]

label variable d_2008 "Y2008" 
label variable quake200Xt2008 "200Km * Y2008" 


quietly{
su total if year==2008 & quake_200==1
local avg_size = round(r(mean),1)
local avg_effect = round(`effect' * `avg_size',1)


noisily: di "************************************"
noisily: di "Average extra votes in a jurisdiction"
noisily: di `avg_effect' " (of an average size of "  `avg_size' ")"
noisily: di "************************************"

total total if quake_200==1 & year==2008
local total_voters_aff = round(_b[total] / 1000000 ,.01)
local total_effect = round(`total_voters_aff' * `effect',.01)

noisily: di "************************************"
noisily: di "Total extra votes in affected areas"
noisily: di `total_effect' "M (where the total voters in affected areas is "  `total_voters_aff' "M)"
noisily: di "************************************" 

}
*

*************************************Table 5: The Effect of Natural Disasters on Incumbents and Competitors
use  "NA_regr.dta", clear

***flood
eststo inc_flood: reghdfe PPP d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
eststo comp_flood1: reghdfe PMLN d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
eststo comp_flood2: reghdfe PMLQ d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
 
eststo parties_flood: reghdfe parties d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
replace total = . if total==0
g lvoters = ln(total)
eststo voter_flood: reghdfe lvoters d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
eststo nei_flood: reghdfe taleb d_2013 affXt2013 neighXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na) 
estadd local extra_row1 "YES"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"

label variable neighXt2013 "Neighbor * Y2013" 
label variable affXt2013 "Affected * Y2013" 


esttab inc_flood comp_flood1 comp_flood2 parties_flood voter_flood  nei_flood using "table5.tex" , f se label ///
scalars("extra_row1 Pashtun * Y2013" "extra_row2 Freq. Flood * Y2013"  "extra_row3 Urban * Y2013")  mgroups("Political Competition" "Political Participation", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) keep(affXt2013 neighXt2013) ///
mtitle("Incumbent" "Competitor 1" "Competitor 2" "Parties" "ln(Turnout)"  "Neighbors") star(* 0.10 ** 0.05 *** 0.01) compress replace 
 

*************************************Table 6: Parallel Trends
use  "NA_regr.dta", clear

eststo aff_na: reghdfe  taleb d_2008 affXt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row2 "NO"
estadd local extra_row3 "NO"
estadd local extra_row4 "NO"
estadd local extra_row5 "NO"

eststo aff_earth: reghdfe  taleb d_2008 affXt2008 quake200Xt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "NO"
estadd local extra_row4 "NO"
estadd local extra_row5 "NO"

eststo freqaff_na: reghdfe  taleb d_2008 affXt2008 quake200Xt2008 pashtoXt2008  if year<2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "NO"
estadd local extra_row5 "NO"

eststo allaff_na: reghdfe  taleb d_2008 affXt2008 quake200Xt2008 earthfreqXt2008 freqXt2008 pashtoXt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"
estadd local extra_row5 "NO"

eststo urban: reghdfe taleb d_2008 affXt2008 quake200Xt2008 earthfreqXt2008 freqXt2008 pashtoXt2008 urbanXt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"
estadd local extra_row5 "YES"

label variable d_2008 "Y2008" 
label variable affXt2008  "Affected * Y2008" 

esttab aff_na aff_earth freqaff_na allaff_na urban using "table6.tex" , f se label  mtitle("Share MMA" "Share MMA" "Share MMA" "Share MMA" "Share MMA") keep(affXt2008) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("extra_row2 Aff. Earthquake * Y2008" "extra_row3 Pashtun * Y2008" "extra_row4 Freq. Distasters * Y2008"  "extra_row5 Urban * Y2008") compress replace 

 
**********************BALANCING
use  "NA_regr.dta", clear

file open myfile using "table7.txt", write replace
file write myfile "\scalebox{1}{\noindent\makebox[\textwidth]{\begin{threeparttable} \label{table:PreLevels} \centering  \begin{tabular}{ l | c c c c } \hline \hline & Not Affected & Affected & Difference & (Std. Error) \\ \hline" _n

su meanfreq if year==2008 & taleb!=.
local mfreq = r(mean)
su pashto if year==2008 & taleb!=.
local mpashto = r(mean)
su urban if year==2008 & taleb!=.
local murban = r(mean)

foreach var of varlist  meanfreq pashto urban{


if `var' == meanfreq {
 local name = "Frequency Floods"
 }
 else if `var' == pashto{
 local name = "Pastun Ethnicity Majority"
 }
       else if `var' == urban{
 local name = "Share Urban Population"
 }
 else {
 local name = "ERROR"
 }
 
 su `var' if affected == 0 & year==2008 & taleb!=.
 local dd = r(mean)
 su `var' if affected == 1 & year==2008 & taleb!=.
 local ee = r(mean)
 
  reg `var' affected if year==2008 & taleb!=.

local diff1 = _b[affected]
local pval1 = ttail(e(df_r),abs(_b[affected]/_se[affected]))*2
local gg = "(" + string(_se[affected],"%8.2f") + ")"
 di `pval1'
 if `pval1'>0.1  {
	local ff = string(`diff1',"%8.2f") 
 } 
 else if `pval1'>0.05 { 
	local ff = string(`diff1',"%8.2f") + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local ff = string(`diff1',"%8.2f") + "$^\star$" + "$^\star$"
 }
 else {
 	local ff = string(`diff1',"%8.2f") + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 
 if `var' == meanfreq |  `var' == pashto {
 file write myfile ("`name'") _tab "&" _tab %8.2f (`dd') _tab "&" _tab %8.2f (`ee') _tab "&" _tab %8.2f ("`ff'") _tab "&" _tab %8.2f ("`gg'") _tab "\\" _n 
 }
 else{
 file write myfile ("`name'") _tab "&" _tab %8.2f (`dd') _tab "&" _tab %8.2f (`ee') _tab "&" _tab %8.2f ("`ff'") _tab "&" _tab %8.2f ("`gg'") _tab "\\ \hline " _n
 }

}

foreach var of varlist  literacy agri hhsize water electric immun popdensity parties taleb{

if `var' == literacy {
 local name = "Literacy Rate"
 }
   else if `var' == agri{
 local name = "Agricultural Emp."
 }
    else if `var' == hhsize{
 local name = "Household Size"
 }
     else if `var' == water{
 local name = "Water Access"
 }
    else if `var' == electric{
 local name = "Electricity Acess"
 }
     else if `var' == immun{
 local name = "$<$5 Years Immunized"
 }
      else if `var' == popdensity{
 local name = "Population Density"
 }
       else if `var' == parties{
 local name = "Num. Parties 2008"
 }
       else if `var' == taleb{
 local name = "MMA Vote Share 2008"
 }
 else {
 local name = "ERROR"
 }
 
 
 reg `var' affected meanfreq pashto urban if year==2008 & taleb!=.

local dd = _b[_cons] + (`mfreq' * _b[meanfreq]) + (`mpashto' * _b[pashto]) + (`murban' * _b[urban])
local ee = _b[_cons] + (`mfreq' * _b[meanfreq]) + (`mpashto' * _b[pashto]) + (`murban' * _b[urban]) + _b[affected]

local diff1 = _b[affected]
local pval1 = ttail(e(df_r),abs(_b[affected]/_se[affected]))*2
local gg = "(" + string(_se[affected],"%8.2f") + ")"
 di `pval1'
 if `pval1'>0.1  {
	local ff = string(`diff1',"%8.2f") 
 } 
 else if `pval1'>0.05 { 
	local ff = string(`diff1',"%8.2f") + "$^\star$"
 }
  else if `pval1'>0.01 { 
	local ff = string(`diff1',"%8.2f") + "$^\star$" + "$^\star$"
 }
 else {
 	local ff = string(`diff1',"%8.2f") + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 
 file write myfile ("`name'") _tab "&" _tab %8.2f (`dd') _tab "&" _tab %8.2f (`ee') _tab "&" _tab %8.2f ("`ff'") _tab "&" _tab %8.2f ("`gg'") _tab "\\" _n 
 
}
*

file write myfile "\hline \hline \end{tabular} 	\begin{tablenotes}[flushleft] \item Note: In the first three rows the table the means of various observables between electoral districts affected and not affected by the 2010 flood. The rest of the rows instead compares conditional means were the controls are the frequency of floods, the share of the population that lives in urban areas and a dummy that indicates Pashtun majority electoral districts. Number of electoral districts Affected is 60. Number of electoral districts Not affected is 45. * p$<$ 0.1, ** p$<$0.05, *** p$<$0.01. \end{tablenotes} \end{threeparttable} }}"
file close myfile

*******************
***APPENDIX*******
******************



*******************FIGURE A1  
use "FTS\funding gap flood decision.dta", clear

drop decisiondate_number amountus decisiondate cumulated_aid

rename funding_gap_decision funding_gap_decision_flood

merge 1:1 day_from_start using "FTS\funding gap earthquake decision.dta"

rename funding_gap_decision funding_gap_decision_earthquake

drop _merge
merge 1:1 day_from_start using "FTS\funding gap haiti decision.dta"

rename funding_gap_decision funding_gap_decision_haiti


drop _merge
merge 1:1 day_from_start using "FTS\funding gap myanmar decision.dta"

rename funding_gap_decision funding_gap_decision_myanmar


drop _merge
merge 1:1 day_from_start using "FTS\funding gap tsunami decision.dta"

rename funding_gap_decision funding_gap_decision_tsunami



drop _merge
merge 1:1 day_from_start using "FTS\funding gap phillipines decision.dta"

rename funding_gap_decision funding_gap_decision_phillipines



twoway (line funding_gap_decision_flood day_from_start ) (line funding_gap_decision_earthquake day_from_start, lc(red) ) (line funding_gap_decision_haiti day_from_start, lp(--) lc(black)) (line funding_gap_decision_myanmar day_from_start, lp(--) lc(gs7)) (line funding_gap_decision_phillipines day_from_start, lp(--) lc(gs10)) (line funding_gap_decision_tsunami day_from_start, lp(--) lc(gs14)) if day_from_start <= 100 , legend(label(1 "2010 Flood Pakistan") label(2 "2005 Earthquake Pakistan") label(3 "2010 Earthquake Haiti") label(4 "2008 Floods Myanmar") label(5 "2009 Floods Philippines") label(6 "2004 Indian Ocean Tsunami")) xtitle("Days From Disaster") ytitle("Funding Gap") graphregion(color(white))

graph export "figureA1.eps", as(eps) name("Graph") preview(off) replace


******************FIGURE A2
use  "NA_regr.dta", clear

sort na year
by na: g ch_taleb = taleb - taleb[_n-1]

label variable ch_taleb "Change in MMA Share"
label variable FGXt2013 "Funding Gap"

lpoly ch_taleb FGXt2013 if year==2013, noscatter ci xlabel(0(0.2)1) ylabel(0(0.02)0.1) title("Effect of Funding Gap on MMA Share") scheme(s2mono)
graph save Graph "figureA2.gph", replace
graph export "figureA2.eps", as(eps) replace
 
 
***************FIGURE A3 
use  "NA_regr.dta", clear

replace camps_distance1=camps_distance1*100
xtreg taleb 1.d_2013 freqXt2013 pashtoXt2013 urbanXt2013 1.affXt2013 c.camps_distance1#1.d_2013 c.camps_distance1#1.affXt2013 ///
c.camps_distance1#c.camps_distance1#1.d_2013 c.camps_distance1#c.camps_distance1#1.affXt2013 ///
c.camps_distance1#c.camps_distance1#c.camps_distance1#1.d_2013 c.camps_distance1#c.camps_distance1#c.camps_distance1#1.affXt2013 if year>2002, fe cluster(na)

margins,  at(camps_distance1=(0(50)400)) dydx(affXt2013)
marginsplot, recastci(rline) ciopts(lp(-)) xlab(0(50)400) yline(0,lc(black)) plotopts(msymbol(none)) tit(Average Effect of 2010 Flood on MMA's share of votes) xtitle(Distance from a JUD camp in Km)  ytitle(Marginal Effect) scheme(s2mono)
graph export "figureA3.pdf", as(pdf) replace


***************FIGURE A4 
use  "NA_regr.dta", clear

reghdfe taleb 1.d_2013 freqXt2013 pashtoXt2013 urbanXt2013 1.affXt2013 c.dist_afgh#1.affXt2013 ///
c.dist_afgh#c.dist_afgh#1.d_2013 c.dist_afgh#c.dist_afgh#1.affXt2013 ///
c.dist_afgh#c.dist_afgh#c.dist_afgh#1.d_2013 c.dist_afgh#c.dist_afgh#c.dist_afgh#1.affXt2013 if year>2002, abs(na) cluster(na)

margins,  at(dist_afgh=(40(10)400)) dydx(affXt2013)
marginsplot, recastci(rline) ciopts(lp(-)) xlab(50(50)400) yline(0,lc(black)) plotopts(msymbol(none)) tit(Average Effect of 2010 Flood on MMA's share of votes) xtitle(Distance of the centroid to the Afghan border in Km)  ytitle(Marginal Effect) scheme(s2mono)
graph export "figureA4.pdf", as(pdf) replace


*************TABLE A1
use  "NA_regr.dta", clear

eststo w2_earth: reghdfe taleb d_2008 quake200Xt2008 earthfreqXt2008 pashtoXt2008 urbanXt2008 [w=total] if year<2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

eststo w8_earth: reghdfe taleb d_2008 quake200Xt2008 earthfreqXt2008 pashtoXt2008 urbanXt2008 [w=total02] if year<2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

eststo w2_flood: reghdfe taleb d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 [w=total] if year>2002 & total>0, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

eststo w8_flood: reghdfe taleb d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 [w=total02] if year>2002 & total>0, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

label variable quake200Xt2008 "Affected * Post" 

esttab w2_earth w8_earth w2_flood w8_flood using "Dropbox\Latest Version\Version190205\weights.tex" , f se label  rename(affXt2013 quake200Xt2008) ///
scalars("extra_row2 Pashtun * Post" "extra_row3 Freq. Disaster * Post"  "extra_row4 Urban * Post")   keep(quake200Xt2008) ///
mtitle("MMA - Earthquake"  "MMA - Flood") star(* 0.10 ** 0.05 *** 0.01) compress replace 
 



*************TABLE A2
use  "NA_regr.dta", clear

eststo eq0:reghdfe taleb0 d_2008 quake200Xt2008 pashtoXt2008 earthfreqXt2008 urbanXt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row1 "Missing = 0"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"
 
eststo eq00:reghdfe taleb00 d_2008 quake200Xt2008 pashtoXt2008 earthfreqXt2008 urbanXt2008 if year<2013, abs(na) cluster(na)
estadd local extra_row1 "Only Recurrent"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"
  
eststo fl0: reghdfe taleb0 d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "Missing = 0"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

eststo fl00: reghdfe taleb00 d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)
estadd local extra_row1 "Only Recurrent"
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

label variable quake200Xt2008 "Affected * Post" 
 

esttab eq0 eq00 fl0 fl00 using "Dropbox\Latest Version\Version190205\def_taleb.tex" , f se label  rename(affXt2013 quake200Xt2008) ///
scalars("extra_row1 Weights" "extra_row2 Freq. Disaster * Post" "extra_row3 Pashtun * Post" "extra_row4 Urban * Post")   mgroups("Earthquake" "Flood", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) keep(quake200Xt2008) ///
mtitle("Share MMA" "Share MMA" "Share MMA" "Share MMA") star(* 0.10 ** 0.05 *** 0.01) compress replace 
  
********TABLE A3
use  "NA_regr.dta", clear

eststo full: reghdfe taleb d_2008 d_2013 affXt2002 affXt2013 quake200Xt2008 quake200Xt2013 earthfreqXt2008  earthfreqXt2013  pashtoXt2008 pashtoXt2013 freqXt2013 freqXt2008 urbanXt2008 urbanXt2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

eststo pmma: reg p_taleb affXt2013 pashtoXt2013 freqXt2013 urbanXt2013 if year==2013 
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"

esttab full pmma using "tableA3.tex" , f se label  mtitle("Share MMA" "P(MMA present)") keep(affXt2013 quake200Xt2008 quake200Xt2013) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("extra_row2 Freq. Distaster * Post" "extra_row3 Pashtun * Post" "extra_row4 Urban * Post") compress replace 


********TABLE A4

use "Final_Data_PA.dta", clear

reghdfe taleb00 post affXpost meanfreqXpost, absorb(pa) cluster(pa)
reghdfe taleb00 post fgXpost meanfreqXpost, absorb(pa) cluster(pa)
ivreg2 taleb00 meanfreqXpost i.paid (fgXpost = affXpost sevXpost) , cluster(pa) first
ivreg2 taleb00 meanfreqXpost i.paid (fgXpost = affXpost sevXpost cap_provXpost) , cluster(pa) first
 
 
************TABLE A5
use  "NA_regr.dta", clear

eststo aff_na: reghdfe  taleb d_2008 d_2013 affXt2008 affXt2013 , abs(na) cluster(na)
estadd local extra_row2 "NO"
estadd local extra_row3 "NO"
estadd local extra_row4 "NO"
estadd local extra_row5 "NO"

eststo aff_earth: reghdfe  taleb d_2008 d_2013 affXt2008 quake200Xt2008 affXt2013 quake200Xt2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "NO"
estadd local extra_row4 "NO"
estadd local extra_row5 "NO"

eststo freqaff_na: reghdfe  taleb d_2008  d_2013 affXt2008 affXt2013 quake200Xt2013 quake200Xt2008 pashtoXt2008 pashtoXt2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "NO"
estadd local extra_row5 "NO"

eststo allaff_na: reghdfe  taleb d_2008  d_2013 affXt2008 quake200Xt2008 affXt2013 quake200Xt2013 freqXt2008 freqXt2013 earthfreqXt2008  earthfreqXt2013 pashtoXt2008 pashtoXt2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"
estadd local extra_row5 "NO"

eststo urban: reghdfe taleb d_2008 d_2013 affXt2008 quake200Xt2008 affXt2013 quake200Xt2013 freqXt2008 freqXt2013 earthfreqXt2008  earthfreqXt2013 pashtoXt2008 pashtoXt2013 urbanXt2008 urbanXt2013, abs(na) cluster(na)
estadd local extra_row2 "YES"
estadd local extra_row3 "YES"
estadd local extra_row4 "YES"
estadd local extra_row5 "YES"

label variable d_2008 "Y2008" 
label variable affXt2008  "Affected * Y2008"

label variable d_2008 "Y2008" 
label variable affXt2008  "Affected * Y2008"  


esttab aff_na aff_earth freqaff_na allaff_na urban using "tableA5.tex" , f se label  mtitle("Share MMA" "Share MMA" "Share MMA" "Share MMA" "Share MMA") keep(affXt2008) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("extra_row2 Aff. Earthquake * Y2008" "extra_row3 Pashtun * Y2008" "extra_row4 Freq. Distasters * Y2008"  "extra_row5 Urban * Y2008") compress replace 

 
**************FALSIFICATION FlOOD
use  "NA_regr.dta", clear

g fake_treat=0
g fake_treatXt2013 = 0
g urbanXt2013 = urban*d_2013

local sim = 1000
set matsize `sim'

mat FAKE = J(`sim',1,1)

forval  i = 1(1)`sim' {
  drop fake_treat fake_treatXt2013
  g fake_treat = 0
	forval na = 1(1)272 {
		local random_draw =  runiform()
		qui: replace fake_treat = 1 if (`random_draw' < 0.4682779) &  (na==`na')
	}
	
	g fake_treatXt2013 = fake_treat * d_2013
	qui: reghdfe taleb d_2013 fake_treatXt2013 urbanXt2013 pashtoXt2013 freqXt2013 if year>2002, abs(na) cluster(na)
	mat FAKE[`i',1] = _b[fake_treatXt2013]
	
	
	
	local per = `i' / `sim'
	
	if `per' == 0.1 {
		di "10%"
	}
	
	if `per' == 0.2 {
		di "20%"
	}
	
	if `per' == 0.3 {
		di "30%"
	}
	
	if `per' == 0.4 {
		di "40%"
	}
	
	if `per' == 0.5 {
		di "50%"
	}
	
	if `per' == 0.6 {
		di "60%"
	}
	
	if `per' == 0.7 {
		di "70%"
	}
	
	if `per' == 0.8 {
		di "80%"
	}
	
	if `per' == 0.9 {
		di "90%"
	}

}
*
if `sim' > 816 {
set obs `sim'
}

g yy = FAKE[_n,1] in 1/`sim'

reghdfe taleb d_2013 affXt2013 freqXt2013 pashtoXt2013 urbanXt2013 if year>2002, abs(na) cluster(na)


hist yy, xline(.0506 , lw(1)) xlabel(-0.055(0.01)0.055) xtitle("{&beta}") freq
graph export "figureA5.pdf",  as(pdf) replace
